/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2024-2024. All rights reserved.
 * Description: local rdma rma buffer implement
 */

#ifndef LOCAL_RDMA_RMA_BUFFER_IMPL_H
#define LOCAL_RDMA_RMA_BUFFER_IMPL_H

#include "hccl_common.h"
#include "hccl_network_pub.h"
#include "rma_buffer.h"
#include "mem_name_repository_pub.h"

namespace hccl {
class LocalRdmaRmaBufferImpl : public RmaBuffer {
public:
	LocalRdmaRmaBufferImpl(const HcclNetDevCtx netDevCtx, void* addr, u64 size, const HcclMemType memType);
    ~LocalRdmaRmaBufferImpl();

    LocalRdmaRmaBufferImpl(const LocalRdmaRmaBufferImpl &that) = delete;
    LocalRdmaRmaBufferImpl &operator=(const LocalRdmaRmaBufferImpl &that) = delete;

    HcclResult Init();
    HcclResult Destroy();

    std::string Serialize();

    inline u32 GetKey() const
    {
        return lkey;
    }

private:
    const       HcclNetDevCtx netDevCtx{nullptr};
    s32         deviceLogicId{-1};
    RdmaHandle  rdmaHandle{nullptr};
    MrHandle    mrHandle{nullptr};
    u32         lkey{0};
    std::string devAddrID{""};
    bool initialized_ = false;
};
}
#endif //  LOCAL_RDMA_RMA_BUFFER_IMPL_H